ucode: support appending array data, similar to socket.send()
authorFelix Fietkau <[email protected]>
Tue, 22 Jul 2025 15:39:21 +0000 (17:39 +0200)
committerFelix Fietkau <[email protected]>
Tue, 22 Jul 2025 15:39:21 +0000 (17:39 +0200)
Signed-off-by: Felix Fietkau <[email protected]>
lib-ucode.c

index 9199f998c977fa736fdcc98b900d70ee16d1ca12..2e63c0bc3558d259fae9c08f822bb4d1bda7d4f7 100644 (file)
@@ -585,23 +585,46 @@ uc_udebug_wbuf_close(uc_vm_t *vm, size_t nargs)
 }
 
 static void
-uc_udebug_wbuf_add_string(struct udebug_buf *buf, uc_value_t *val)
+uc_udebug_wbuf_append(uc_vm_t *vm, struct udebug_buf *buf, uc_value_t *val)
 {
-       udebug_entry_init(buf);
-       udebug_entry_append(buf, ucv_string_get(val), ucv_string_length(val));
-       udebug_entry_add(buf);
+       struct printbuf *pb;
+       size_t len;
+
+       if (!val)
+               return;
+
+       switch (ucv_type(val)) {
+       case UC_STRING:
+               udebug_entry_append(buf, ucv_string_get(val), ucv_string_length(val));
+               break;
+       case UC_ARRAY:
+               len = ucv_array_length(val);
+               for (size_t i = 0; i < len; i++)
+                       uc_udebug_wbuf_append(vm, buf, ucv_array_get(val, i));
+               break;
+       default:
+               pb = xprintbuf_new();
+               ucv_to_stringbuf(vm, pb, val, false);
+               udebug_entry_append(buf, pb->buf, pb->bpos);
+               printbuf_free(pb);
+               break;
+       }
 }
 
+
+
 static uc_value_t *
 uc_udebug_wbuf_add(uc_vm_t *vm, size_t nargs)
 {
        struct udebug_buf *buf = uc_fn_thisval("udebug.wbuf");
        uc_value_t *arg = uc_fn_arg(0);
 
-       if (!buf || ucv_type(arg) != UC_STRING)
+       if (!buf || !arg)
                return NULL;
 
-       uc_udebug_wbuf_add_string(buf, arg);
+       udebug_entry_init(buf);
+       uc_udebug_wbuf_append(vm, buf, arg);
+       udebug_entry_add(buf);
 
        return ucv_boolean_new(true);
 }